package com.fallsvc.re.javasesets.reflectemunlambda.lambda;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.function.BiConsumer;
import java.util.function.Consumer;

/**
 * @auther falls_vc
 * description:
 * @date 2025/10/26  23:27
 */
public class Demo1 {
    public static void main1(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("Hello");
        list.add("bit");
        list.add("hello");
        list.add("lambda");
        list.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.print(s + " ");
            }
        });
        System.out.println();
        //表示调用一个，不带有参数的方法，其执行花括号内的语句，为原来的函数体内容
        list.forEach(s-> System.out.print(s + " "));
    }
    public static void main2(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("Hello");
        list.add("bit");
        list.add("hello");
        list.add("lambda");
//        list.sort(new Comparator<String>() {
//            @Override
//            public int compare(String str1, String str2){
////注意这里比较长度
//                return str1.length()-str2.length();
//            }
//        });

        list.sort((s1,s2)->
                s1.length() - s2.length()
        );

        System.out.println(list);


    }
    public static void main(String[] args) {
        HashMap<Integer, String> map = new HashMap<>();
        map.put(1, "hello");
        map.put(2, "bit");
        map.put(3, "hello");
        map.put(4, "lambda");
//        map.forEach(new BiConsumer<Integer, String>(){
//            @Override
//            public void accept(Integer k, String v){
//                System.out.println(k + "=" + v);
//            }
//        });
        map.forEach((k,v) ->
                System.out.println(k + "=" + v)
        );
    }
}
